package com.qfedu.mapper;

import com.qfedu.model.Project;
import com.qfedu.model.Stage;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/6/30 20:36
 */

public interface StageMapper {

    @Results(id = "stageMap",value = {
            @Result(column = "sid",property = "sid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "pid",property = "project",javaType = Project.class,one =
            @One(select = "com.qfedu.mapper.ProjectMapper.findProject",fetchType = FetchType.EAGER)
            )
    })
    // 分页查询
    @Select("select * from stage where status = 1 limit #{currentPage},#{pageSize}")
    List<Stage> findPage(@Param("currentPage") int currentPage,@Param("pageSize") int pageSize);

    @Select("select count(*) from stage where status = 1")
    Long count();

    @Insert("insert into stage (sid,sname,starttime,endtime,updatetime,pid)" +
            "values (#{sid},#{sname},#{starttime},#{endtime},#{updatetime},#{pid})")
    int addStage(Stage stage);

    @ResultMap("stageMap")
    @Select("select * from stage where sid = #{sid} and status = 1")
    Stage findBySid(String sid);

    @Update("update stage set sname=#{sname},updatetime=now(),pid=#{pid} where sid =#{sid}")
    int updateStage(Stage stage);

    @Update("update stage set status = 0 where sid = #{sid}")
    int deleteBySid(String sid);
}
